<?php
/**
 *
 * @author griever
 * @version
 */
require_once 'Base.php';
require_once 'Zend/Loader/PluginLoader.php';
require_once 'Zend/Controller/Action/Helper/Abstract.php';

/**
 * CheckCaptcha Action Helper
 *
 * @uses actionHelper Custom_Helper
 */
class Custom_Helper_CheckCaptcha extends Dummy_Helper_Base
{
	public function checkCaptcha($captchaChallenge, $captchaResponse)	{
		$error = null;
//		$captchaCheck = false;
//		$captchaSession = new Zend_Session_Namespace('Zend_Form_Captcha_' . $captchaId);
//		$captchaWord = $captchaSession->word;
//		if( $captchaWord ) {
//			if( $captcha === $captchaWord ){
//				$captchaCheck = true;
//			}
//		}
		$recaptcha = new Zend_Service_ReCaptcha(ReCaptchaConfig::$pubKey, ReCaptchaConfig::$privKey);
		$result = $recaptcha->verify($captchaChallenge, $captchaResponse);
		if (!$result->isValid())
		{
			$error = Message::CAPTCHA_INVALID;
		}
		return $error;
	}

	/**
	 * Strategy pattern: call helper as broker method
	 */
	public function direct($captcha, $captchaResponse){
		// TODO Auto-generated 'direct' method
		return $this->checkCaptcha($captcha, $captchaResponse);
	}
}

